/**
 * 竞争者信息添加
 * Created by wenchuan.li on 2018/07/12 18:23.
 */
define(function () {

    var self,
        app = win.app,
        subData = {
            GWBJNAME: '',//商机主题
            GWBJSEQ:'',
            GWBJID: '',//客户编号
            GWBJ001: '',//竞争对手
            GWBJ002: '',//产品描述
            GWBJ003: '',//优点
            GWBJ004: '',//缺点
            GWBJ005: '1'//竞争等级
        },
        pageParameters
    ;

    var JzxxAdd = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _readyBefore: function () {
                    pageParameters = self._pageParameters;
                }
            }, win);

            if (pageParameters._targer == 'jzxx-add') {
                subData.GWBJNAME = pageParameters.GWBJNAME;
                subData.GWBJID = pageParameters.GWBJID;
            } else {
                app.extend(subData, pageParameters.item);
            }

        },
        add:function () {
            app.ajax({
                xurl: "api/wx/gwat161/jzxxAdd",
                loading: true,
                xdata: subData,
                confirm: {
                    msg:'确认添加？'
                },
                cb: function (result) {
                    if (result.ok) {
                        app.alert({
                            msg: '添加成功！',
                            ok: function () {
                                app.back(1);
                            }
                        });
                        pageParameters.cb();
                    }
                }
            });
        },
        edit:function () {
            app.ajax({
                xurl: "api/wx/gwat161/jzxxEdit",
                loading: true,
                xdata: subData,
                confirm: {
                    msg:'确认修改？'
                },
                cb: function (result) {
                    if (result.ok) {
                        app.alert({
                            msg: '修改成功！',
                            ok: function () {
                                app.back(1);
                            }
                        });
                        pageParameters.cb();
                    }
                }
            });
        },
        _lazy: function () {
            this._super();
            new Vue({
                el: app.getByid(doc, 'adressCont'),
                data: {
                    sub: subData
                },
                methods: {
                    editJzxx: function () {
                        if (pageParameters._targer == 'read') {
                            return;
                        }
                        if (subData.GWBJ001.trim() == '') {
                            app.toast('请输入竞争对手');return false;
                        }
                        if (subData.GWBJ002.trim() == '') {
                            app.toast('请输入产品描述');return false;
                        }
                        if (subData.GWBJ003.trim() == '') {
                            app.toast('请输入优点');return false;
                        }
                        if (subData.GWBJ004.trim() == '') {
                            app.toast('请输入缺点');return false;
                        }

                        if (pageParameters._targer == 'jzxx-add') {
                            self.add();
                        } else {
                            self.edit();
                        }
                    }
                }
            });

        },
        _ready: function () {

        }
    });

    return new JzxxAdd();

});